/**
 * @author GML Enterprise Solutions
 * Copyright 2011 GML Enterprise Solutions
 * 
 * This file is part of SimpleORM.
 *
 * SimpleORM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *   
 * SimpleORM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with SimpleORM.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package com.gmles.simpleorm.common;

import java.lang.reflect.Array;

public class ArrayAccessor extends SQLAccessor{
	private Integer index;
	private Class<?> type;
	
	public ArrayAccessor(Integer index, Class<?> componentType){
		this.index = index;
		this.type = componentType;
	}

	@Override
	protected Object getObject(Object object) {
		return object==null?null:Array.get(object, index);
	}

	@Override
	protected void putObject(Object object, Object value) {
		Array.set(object, index, value);
	}

	@Override
	public Class<?> getType() {
		// TODO Auto-generated method stub
		return type;
	}
	
	@Override
	public Class<?> getComponentType(){
		return type.getComponentType();
	}
}
